import trans from "./translate";

export const testRule = (msg: string) => [
  { required: true, message: msg },
  {
    pattern: new RegExp(/^[a-zA-Z\u4e00-\u9fa5]+/, 'g'),
    message: '只能中英文开头',
  },
  {
    pattern: new RegExp(/^[a-zA-Z0-9\u4e00-\u9fa5\-_.]+/, 'g'),
    message: '不可包含特殊字符',
  },
  { pattern: new RegExp(/^\S*\S+\S*$/, 'g'), message: '不能包含空格等空白符' },
  {
    pattern: new RegExp(/^[a-zA-Z0-9\u4e00-\u9fa5\-_.\s]{1,20}$/, 'g'),
    message: '不能超过20个字符',
  },
];

export const nameRule = (msg?: string) => {
  return [
    { required: true, message: msg },
    {
      pattern: /^([\u4e00-\u9fa5a-zA-Z])([\w\-\.\u4e00-\u9fa5]){0,20}$/g,
      message: trans('rule.name')
    }
  ]
}
